package com.example.myweb.Config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "cors") // 指定前缀
public class CorsProperties {

    private String allowedOrigins = "*"; // 默认允许所有来源
    private String allowedMethods = "GET,POST,PUT,DELETE"; // 设置默认允许的方法
    private String allowedHeaders;
    private boolean allowCredentials;
    private Long maxAge;

    // --- 必须要有所有字段的 Getter 和 Setter ---
    public String getAllowedOrigins() {
        return allowedOrigins != null ? allowedOrigins : "*";
    }

    public void setAllowedOrigins(String allowedOrigins) {
        this.allowedOrigins = allowedOrigins;
    }

    public String getAllowedMethods() {
        return allowedMethods;
    }

    public void setAllowedMethods(String allowedMethods) {
        this.allowedMethods = allowedMethods;
    }

    public String getAllowedHeaders() {
        return allowedHeaders;
    }

    public void setAllowedHeaders(String allowedHeaders) {
        this.allowedHeaders = allowedHeaders;
    }

    public boolean isAllowCredentials() { // boolean 类型的 getter 是 isXxx()
        return allowCredentials;
    }

    public void setAllowCredentials(boolean allowCredentials) {
        this.allowCredentials = allowCredentials;
    }

    public Long getMaxAge() {
        return maxAge;
    }

    public void setMaxAge(Long maxAge) {
        this.maxAge = maxAge;
    }
}